/* eslint-disable react/jsx-no-duplicate-props */
import React, {Component} from 'react'
import {connect} from 'react-redux';
import {Button, Form} from 'antd';
import {ProFormText} from '@ant-design/pro-form';
import {removeEmptyField} from '../../compoent/emptyFild'

class Add extends Component {
    constructor(props) {
        super(props);
        this.state = {
            data: [],
            visible: false,
        };
    }


    onFinish = (values) => {
        let params = removeEmptyField(values);
        if (params) {
            this.props.addVip(params).then(res => {
                this.props.list()
            })
        }
        this.props.handleCancel()

    };

    onFinishFailed = (errorInfo) => {

    };


    render() {
        return (
            <div>
                <Form name="basic"
                      labelCol={{span: 6}}
                      wrapperCol={{span: 14}}
                      initialValues={{remember: true}}
                      onFinish={this.onFinish}
                      onFinishFailed={this.onFinishFailed}
                      autoComplete="off"
                >
                    <ProFormText rules={[
                        {
                            required: true,
                            message: '请输入内容!',
                        },
                    ]} width="md" name="unit" label="类型" placeholder="描述 "/>


                    <ProFormText tooltip="价格" width="md" name="price" label="销售价格"
                                 placeholder="价格"
                                 rules={[
                                     {
                                         required: true,
                                         message: '价格!',
                                     }
                                 ]}
                    />
                    <ProFormText tooltip="时长 单位/月" width="md" name="time" label="时长"
                                 placeholder="销售时长"
                                 rules={[
                                     {
                                         required: true,
                                         message: '销售时长!',
                                     }
                                 ]}
                    />
                    <ProFormText tooltip="原价(非真实价格)" width="md" name="originPrice" label="原价"
                                 placeholder="原价"
                                 rules={[
                                     {
                                         required: true,
                                         message: '原价!',
                                     }
                                 ]}
                    />
                    <ProFormText tooltip="立省" width="md" name="remarks" label="立省"
                                 placeholder="立省"
                                 rules={[
                                     {
                                         required: true,
                                         message: '立省!',
                                     }
                                 ]}
                    />

                    <Form.Item wrapperCol={{offset: 8, span: 16}}>
                        <Button type="success" htmlType="reset">
                            重置
                        </Button>
                        <Button  type="primary" htmlType="submit" style={{marginLeft: 30}}>
                            提交
                        </Button>

                    </Form.Item>
                </Form>
            </div>
        )


    }


}

const mapState = state => ({
    ...state.vip

});

const mapDispatch = dispatch => ({
    ...dispatch.vip
})

export default connect(mapState, mapDispatch)(Add);